package com.minsu.controller;


import com.minsu.entity.*;
import com.minsu.service.FuelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/fuel")
public class FuelController {

    @Autowired
    private FuelService fuelService;

    /**
     * 查询所有的炉料的信息
     */

    @GetMapping
    public Result findAllFuel(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        log.info("分页查询炉料信息，页码：{}，每页数量：{}", pageNum, pageSize);

        // 创建分页请求对象
        PageRequest pageRequest = new PageRequest();
        pageRequest.setPageNum(pageNum);
        pageRequest.setPageSize(pageSize);

        // 获取分页结果
        PageResult<Fuel> pageResult = fuelService.findAllFuel(pageRequest);

        return Result.success(pageResult);
    }

//    @GetMapping
//    public Result findAllFuel(@RequestParam(defaultValue = "1") Integer pageNum,
//                              @RequestParam(defaultValue = "10") Integer pageSize) {
//        log.info("分页查询炉料信息，页码：{}，每页数量：{}", pageNum, pageSize);
//        List<Fuel> fuelList = fuelService.findAllFuel(pageNum, pageSize);
//        return Result.success(fuelList);
//    }
//    @GetMapping
//    public Result findAllFuel() {
//        log.info("查询所有的炉料的信息");
//        List<Fuel> fuelList  =  fuelService.findAllFuel();
//
//        return Result.success(fuelList);
//
//    }

    /**
     *增加炉料的信息
     */
    @PostMapping("/addFuel")
    public Result addFuel(@RequestBody Fuel fuel){
        log.info("新增炉料的信息,{}",fuel);
        fuelService.addFuel(fuel);
        return Result.success();
    }

    /**
     * 根据batchNo删除炉料的信息
     * @param batchNo
     * @return
     */
    @DeleteMapping("/{batchNo}")
    public Result deleteFuel(@PathVariable String batchNo){
        log.info("根据id删除炉料的信息,{}",batchNo);
        fuelService.deleteById(batchNo);
        return Result.success();
    }

    /**
     * 根据batchNo查询的炉料的信息
     */
    @GetMapping("/{batchNo}")
    public Result findByBatchNo(@PathVariable String batchNo){
        log.info("根据id查询的炉料的信息:{}",batchNo);
        Fuel fuelList  =  fuelService.findByBatchNo(batchNo);

        return Result.success(fuelList);
    }

    /**
     * 修改炉料的信息
     *
     */
    @PutMapping
    public Result updateFuel(@RequestBody Fuel fuel){
        log.info("修改炉料的信息,{}",fuel);
        fuelService.updateFuel(fuel);
        return Result.success();
    }

}
